﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ProgNetComponents.Design.TypeConverters;

namespace ProgNetComponentsDx.Data.Design
{
    public class RecordSelectStructTypeConverter : CollectionItemTypeConverter<RecordSelectStruct>
    {
        protected override System.Reflection.ConstructorInfo GetConstructor(RecordSelectStruct item)
        {
           if (item.DataBaseTableName != item.DataSetTableName)
            {
                return typeof(RecordSelectStruct).GetConstructor(new Type[] { typeof(string), typeof(string), typeof(string) });
            }
            else if (item.SelectString != ("SELECT * FROM " + item.DataBaseTableName))
            {
                return typeof(RecordSelectStruct).GetConstructor(new Type[] { typeof(string), typeof(string) });
            }
            else
            {
                return typeof(RecordSelectStruct).GetConstructor(new Type[] { typeof(string) });
            }
        }

        protected override object[] GetConstructorParamters(RecordSelectStruct item)
        {
           if (item.DataBaseTableName != item.DataSetTableName)
            {
                return new object[] { item.SelectString, item.DataSetTableName, item.DataBaseTableName };
            }
            else if (item.SelectString != ("SELECT * FROM " + item.DataBaseTableName))
            {
                return new object[] { item.SelectString, item.DataSetTableName };
            }
            else
            {
                return new object[] { item.DataSetTableName };
            }
        }
    }
}